package com.sky.demo.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author sky
 * @Description:
 * @date 2015/7/31 11:32
 */
public class WaterFallAdapter extends RecyclerAdapter {

    private List<Integer> mHeight;
    private List<Integer> mWidth;

    public WaterFallAdapter(Context context, List<String> mDatas) {
        super(context, mDatas);
        mHeight = new ArrayList<>();
        mWidth = new ArrayList<>();
        for (int i = 0; i < mDatas.size(); i++) {
            mWidth.add((int) (Math.random() * 127 + 200));
            mHeight.add((int) (Math.random() * 255 + 200));
        }
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        if (mWidth.size() < getItemCount()) {
            for (int i = mWidth.size(); i < getItemCount(); i++) {
                mWidth.add((int) (Math.random() * 127 + 200));
                mHeight.add((int) (Math.random() * 255 + 200));
            }
        }

        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        lp.height = mHeight.get(position);
        lp.width = mWidth.get(position);
        holder.itemView.setLayoutParams(lp);


    }
}
